package org.ocean.general.sample.page;
import org.ocean.general.sample.helper.PageHelper;

import java.util.ArrayList;
import java.util.List;

public class PageInfo<T>{
    private int page;
    private int size;
    private List<T> list;
    private int totalCount;
    private int startOffset;
    private int endOffset;
    private String specifyFiled;

    public String getSpecifyFiled() {
        return specifyFiled;
    }

    public void setSpecifyFiled(String specifyFiled) {
        this.specifyFiled = specifyFiled;
    }

    private boolean calcSwitch;

    public boolean isCalcSwitch() {
        return calcSwitch;
    }

    public void setCalcSwitch(boolean calcSwitch) {
        this.calcSwitch = calcSwitch;
    }
    public PageInfo(){
        this.list = new ArrayList<>();

    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getStartOffset() {
        return startOffset;
    }

    public void setStartOffset(int startOffset) {
        this.startOffset = startOffset;
    }

    public int getEndOffset() {
        return endOffset;
    }

    public void setEndOffset(int endOffset) {
        this.endOffset = endOffset;
    }

    public void initBetweenPageInfo(){
        if (this.page == 1) {
            this.startOffset = this.page;
            this.endOffset = this.size;
        } else {
            this.startOffset = (this.size * this.page) - this.size + (this.page - 1);
            this.endOffset = this.page * this.size + (this.page - 1);
        }
    }
    public void initPageInfo(){
        if (this.page == 1) {
            this.page = 0;
        } else {
            this.page = (this.page - 1);
        }
        int startSize = this.page * this.size;
        this.startOffset = startSize;
        this.endOffset = this.size;
    }

    public void startPageInfo(){
        this.initPageInfo();
        PageHelper.set(this);
    }
}
